package com.ewili.x.special.service.data.impl;

import com.alibaba.fastjson.JSONObject;
import com.ewili.framework.utils.HttpClientUtils;
import com.ewili.framework.utils.ObjectHttpClientUtils;
import com.ewili.x.special.service.data.inter.ExecsMarketService;
import com.ewili.x.special.task.thread.inter.ExecsMarketThreadTask;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ExecsMarketServiceImpl implements ExecsMarketService {

    @Autowired
    ExecsMarketThreadTask execsMarketThreadTask;

    @Override
    public void spideExecsMarket() {
        String baseUrl = "http://datacenter.eastmoney.com/api/data/get?st=tdate&sr=-1&p=1&ps=50&sty=ALL&token=28dfeb41d35cc81d84b4664d7c23c49f&var=HtHcMiDN&filter=(type=%221%22)&type=RPTA_WEB_GGSCTJ&rt=52497041";
        String content = HttpClientUtils.getContent(baseUrl, 300000, 300000);
        JSONObject baseObject = ObjectHttpClientUtils.formatEastMoneyJson(content, "var HtHcMiDN=").getJSONObject("result");
        Integer pages = baseObject.getInteger("pages");
        for (int i = 1; i <= pages; i++) {
            String url = "http://datacenter.eastmoney.com/api/data/get?st=tdate&sr=-1&p=" + i + "&ps=50&sty=ALL&token=28dfeb41d35cc81d84b4664d7c23c49f&var=HtHcMiDN&filter=(type=%221%22)&type=RPTA_WEB_GGSCTJ&rt=52497041";
            execsMarketThreadTask.execsMarket(url);
        }
    }
}
